package com.yzh.openai.config;

import com.yzh.openai.handler.LoginInterceptor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器配置
 * 登录请求放行、其余拦截
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Value("${app.config.api-version}")
    private String apiVersion;
    
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns(
                        "/api/" + apiVersion + "/chat/completions",
                        "/api/" + apiVersion + "/sale/**",
                        "/api/" + apiVersion + "/auth/userInfo",
                        "/api/" + apiVersion + "/tool/**"
                )
                .excludePathPatterns("/api/" + apiVersion + "/auth/login", "/api/" + apiVersion + "/sale/pay_notify");
    }
}
